Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Text
Imports System.Windows
Imports System.Windows.Controls
Imports System.Windows.Data
Imports System.Windows.Documents
Imports System.Windows.Input
Imports System.Windows.Media
Imports System.Windows.Media.Imaging
Imports System.Windows.Shapes
Imports System.Data
Imports System.Configuration
Imports System.Xml

Namespace SimpleChart.Charts
    ''' <summary> 
    ''' Interaction logic for ChartPlayGround.xaml 
    ''' </summary> 
    Partial Public Class ChartPlayGround
        Inherits Window
        Public Sub New()
            InitializeComponent()

            DrawChart()
        End Sub

        Private Sub DrawChart()
            ' Resets the values 
            chart1.Reset()

            ' Setting this property provides angled dimension to the X-axis for more readability 
            chart1.SmartAxisLabel = True

            ' Set the chart title 
            chart1.Title = "Sales by Branch"

            ' Set the Y-Axis value 
            chart1.ValueField.Add("CollectedAmount")

            ' Set the chart tooltip. {field} will be replaced by current bar value. 
            ' Need to improve in this little templating. 
            chart1.ToolTipText = "Sales($): {field}"

            ' Set the x-axis text 
            chart1.XAxisText = "Sales"

            ' Set the x-axis data field 
            chart1.XAxisField = "Branch_Name"

            ' Setting this value displays the bar value on top of the bar. 
            chart1.ShowValueOnBar = True

            ' Get the data required for displaying the graph. 
            Dim db As New Global_Visas_Data_Layer.DataAccess
            'Dim dt As DataTable = db.GetSQLDataTable("exec branchcashin")
            Dim ds As DataSet = db.GetSQLDataSet("exec branchcashin")
            '= New DataSet("Sales")
            ds.Tables(0).TableName = "Sales"
            Dim dsetAll As DataSet = ds
            'QueryHelper.GetDataSet(ConfigurationManager.AppSettings("SALES_XML"))

            ' Set the datasource 
            chart1.DataSource = dsetAll

            '' Generate the Graph 
            chart1.Generate()


            '' Draw CHART 2. 
            '' Reset the chart 
            'chart2.Reset()

            '' Setting this property provides angled dimension to the X-axis for more readability 
            'chart2.SmartAxisLabel = False

            '' Set the chart title 
            'chart2.Title = "Sales Summary by Region"

            '' Add the range of values to the chart. 
            'chart2.ValueField.Add("Min")
            'chart2.ValueField.Add("Max")
            'chart2.ValueField.Add("Avg")

            '' Set the chart tooltip. {field} will be replaced by current bar value. 
            '' Need to improve in this little templating. 
            'chart2.ToolTipText = "Sales($): {field}"

            '' Set the x-axis text 
            'chart2.XAxisText = "Sales"

            '' Set the x-axis field 
            'chart2.XAxisField = "Region"

            '' Setting this value displays the bar value on top of the bar. 
            'chart2.ShowValueOnBar = True

            '' Get the data 
            ''Dim db As New Global_Visas_Data_Layer.DataAccess
            ''dt = db.GetSQLDataTable("exec branchcashin")
            ''ds = New DataSet
            ''ds.Tables.Add(dt)
            ''dsetAll = ds

            '' Assign to datasource 
            'chart2.DataSource = dsetAll

            '' Generate the chart 
            'chart2.Generate()
        End Sub

        '    Private Function TableToElem(ByVal objTable As DataTable) As XmlElement

        '        Dim objDOM As XmlDocument = New XmlDocument
        '        Dim objRoot As XmlElement = objDOM.CreateElement("results")
        '        Dim objRow As DataRow
        '        Dim objElem As XmlElement
        '        'Dim lngPos As Integer
        '        Dim objCol As DataColumn

        '        ' iterate table contents
        '        For Each objRow In objTable.Rows
        '            objElem = objDOM.CreateElement("row")

        '            ' iterate columns
        '            For Each objCol In objTable.Columns
        '                If Not objRow.IsNull(objCol.ColumnName) Then
        '                    objElem.SetAttribute(objCol.ColumnName, objRow.Item(objCol.ColumnName))
        '                Else
        '                    objElem.SetAttribute(objCol.ColumnName, "")
        '                End If
        '            Next
        '            objRoot.AppendChild(objElem)
        '        Next
        '        Return objRoot

        '    End Function
    End Class
End Namespace
